﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileManager;
using System.Web;

namespace DalatCooking.Core.Web.HttpHandlers
{
    public class FileUploadBase
    {
        public static bool FileUpload(HttpPostedFile postedFile, ref string errMess, ref string path)
        {
            string _uploadFolder = Setting.String("FILE_IMAGEFOLDER");

            string _imageResizedPath = Setting.String("FILE_IMAGEFOLDER");

            UploadHandler upload = new UploadHandler();

            upload.AllowedExtensions = Setting.String("FILE_ALLOW_IMAGEEXT");
            upload.GenerateUniqueFileName = Setting.Boolean("FILE_ALLOW_UNIQUENAME");

            upload.VirtualSavePath = _uploadFolder;
            upload.FileContentLenght = Setting.Int("FILE_MAXSIZE");
            upload.OverwriteExistingFile = Setting.Boolean("FILE_ALLOW_OVERWRITE");
            upload.GenerateDateFolder = Setting.Boolean("FILE_ALLOW_DATEFOLDER");
            upload.AddTextOnImage = Setting.Boolean("IMAGE_ALLOW_ADDTEXT");
            upload.ResizeImage = Setting.Boolean("IMAGE_ALLOW_RESIZE");

            int imageWidth = Setting.Int("IMAGE_WIDTH");
            int imageHeight = Setting.Int("IMAGE_HEIGHT"); 
            try
            {
                return upload.UploadFile(postedFile, ref errMess, ref path);
            }
            catch { return false; }
        }
    }
}
